import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';

class PermissionUtil {
  static Future<bool> checkPermissionPhotos(BuildContext context,
      {bool showAlert = false}) async {
    Permission permission = Permission.storage;
    PermissionStatus status = await permission.status;
    if (status.isGranted) {
      debugPrint('权限');
      // 有权限
      return true;
    } else if (status.isDenied) {
      debugPrint('权限拒绝');
      //权限拒绝， 需要区分IOS和Android，二者不一样
      // requestPermission(permission);
      return false;
    } else if (status.isPermanentlyDenied || status.isRestricted) {
      debugPrint('权限永久拒绝');
      //权限永久拒绝，且不在提示，需要进入设置界面，IOS和Android不同
      // showDialog<String>(
      //   context: context,
      //   builder: (BuildContext buildContext) => AlertDialog(
      //     title: const Text('你已关闭手机相册相册权限'),
      //     content: const Text('请到手机设置开启相册权限'),
      //     actions: <Widget>[
      //       // if user deny again, we do nothing
      //       TextButton(
      //         onPressed: () => Navigator.pop(buildContext),
      //         child: const Text('不开启'),
      //       ),

      //       // if user is agree, you can redirect him to the app parameters :)
      //       TextButton(
      //         onPressed: () {
      //           Navigator.pop(buildContext);
      //           openAppSettings();
      //         },
      //         child: const Text('去开启'),
      //       ),
      //     ],
      //   ),
      // );
      return false;
    } else {
      debugPrint('第一次申请');
      //第一次申请
      // requestPermission(permission);
      return false;
    }
  }
}
